//============================================================================
// Name        : ms007.cpp
// Author      : Tadas
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include "lib.h"
using namespace std;

int main() {
	 const int n = 4;
		double **a, **at, b[n], bt[n], x[n], ats;
		int i, k;

		
		a = alloc(n, n);
		at= alloc(n, n);
		a[0][0] = 1; a[0][1] = 5; a[0][2] = 2; a[0][3] =4;
		a[1][0] = 4; a[1][1] = 1; a[1][2] = 3; a[1][3] =1;
		a[2][0] = 2; a[2][1] = 2; a[2][2] = 1; a[2][3] =4;
		a[3][0] = 3; a[3][1] = 2; a[3][2] = 1; a[3][3] =5;
		b[0] = 1; b[1] = 6; b[2] = 2; b[3] = 4;

	/*	a[0][0] = 1; a[0][1] = 2; a[0][2] = 3;
		a[1][0] = 4; a[1][1] = 5; a[1][2] = 6;
		a[2][0] = 3; a[2][1] = 2; a[2][2] = 3;
		b[0] = 3; b[1] = 4; b[2] = 5;*/

		for (i = 0; i < n; i++) {
		for (k = 0; k < n; k++)
			at[i][k] = a[i][k];
		bt[i] = b[i];
	}
		
	gausjord(a, b, x, n);

	for (i = 0; i < n; i++) {
		ats = 0;
		for (k = 0; k < n; k++)
			ats += at[i][k] * x[k];
		printf("%f\t%f\t%f\n", x[i], ats, bt[i]);
	}

	return 0;
}
